In [2]:
import gpkit
import gpkit.interactive
Suppose that 400 cubic yards of gravel must be ferried across a river. Suppose that the gravel is to be shipped in an open box of length $t_1$, width $t_2$, and height $t_3$. The sides and bottom of the box cost \$10 per square yard and the ends of the box cost \$20 per squared yard. The box will have no salvage value and each round trip of the box on the ferry will cost 10 cents. What is the minimum cost of transporting the 400 cubic yards of gravel?
In [3]:
# transporting gravel across a river:
# how large of a box should be used / how many trips should be taken?
V1 = gpkit.Variable("V_1", 400, "cubic yards", "volume of gravel to transport")
l = gpkit.Variable("l", "yards", "box length")
w = gpkit.Variable("w", "yards", "box width")
h = gpkit.Variable("h", "yards", "box height")
c_sides = gpkit.Variable("c_{sides}", 10, "1/yard^2", "cost of box sides and bottom")
c_ends = gpkit.Variable("c_{ends}", 20, "1/yard^2", "cost of box ends")
c_ferry = gpkit.Variable("c_{ferry}", 0.10, "-", "cost of ferry trip")
A_end = w*h
A_side = l*h
A_bottom = w*l
total_cost = c_ferry*V1/(l*w*h) + c_ends*2*A_end + c_sides*(2*A_side + A_bottom)
gp = gpkit.GP(total_cost)
sol = gp.solve()
print sol.table()
As above, except to facilitate handling of the box it is required that its height be 1 yard.
In [4]:
gp.sub(h, 1)
sol = gp.solve()
print sol.table()
Now instead of setting the height, it is required that the sides and bottom of the box are made from scrap material. Only four square yards of this scrap material are available.
In [5]:
A_scrap = gpkit.Variable("A_{scrap}", 4, "yards^2", "scrap material available")
gp = gpkit.GP(c_ferry*V1/(l*w*h) + c_ends*2*A_end,
[2*A_side + A_bottom <= A_scrap])
gp
Out[5]:
In [6]:
print gp.solve().table()
In [7]:
L = gpkit.Variable("L", 1, "yards", "total fence length")
l = gpkit.Variable("l", "yards", "plot side parallel to river")
w = gpkit.Variable("w", "yards", "plot side perpendicular to river")
A_plot = l*w
gp = gpkit.GP(1/A_plot, [2*w + l <= L])
sol = gp.solve()
print sol.table()
In [8]:
R = gpkit.Variable("R", 1, "inches", "log radius")
d = gpkit.Variable("d", "inches", "beam depth")
w = gpkit.Variable("w", "inches", "beam width")
gp = gpkit.GP(1/(w*d**3), [(d/2)**2 + (w/2)**2 <= R**2])
sol = gp.solve()
print sol.table()
In [9]:
L = gpkit.Variable("L", 1, "inches", "tin sheet side length")
l = gpkit.Variable("l", "inches", "box length")
w = gpkit.Variable("w", "inches", "box width")
h = gpkit.Variable("h", "inches", "box height")
cx = gpkit.Variable("c_x", "inches", "corner cutout length in x dimension")
cy = gpkit.Variable("c_y", "inches", "corner cutout length in y dimension")
gp = gpkit.GP(1/(l*w*h),
[L >= w + 2*cx,
L >= l + 2*cy,
cx >= h,
cy >= h])
sol = gp.solve()
print sol.table()
Ivan Petrovich is a brilliant student of psychology and mathematics. Unfortunately, after his second year of graduate study he had to take a year off to recoup his finances. He worked as a consultant to Z corporation, his recompense being strictly proportional to his productivity. After a thorough study of his productivity, Ivan concluded that his recompense would be
$ \$ 0.5 \tau_W^{1.5} \tau_S^{0.75} \tau_M^{0.1} $ per day,
where $\tau_W$, $\tau_S$, and $\tau_M$ are the hours spent each day in work, in sleep, and in listening to new classical records. Ivan was under strict doctor's orders to take at least three hours a day for his meals, during which he could, however, also listen to music. His only variable expense was the purchase of new records, which cost $ \$ 5 \tau_M $. Ivan therefore allotted his time to maximize
$ \$ 0.5 \tau_W^{1.5} \tau_S^{0.75} \tau_M^{0.1} - \$ 5 \tau_M $
subject, of course, to the condition
$ \tau_W + \tau_S + 3 \leq 24$.
How did Ivan allot his time?
In [10]:
tw = gpkit.Variable("\\tau_W", "-", "hours spent working")
ts = gpkit.Variable("\\tau_S", "-", "hours spent sleeping")
to = gpkit.Variable("\\tau_O", "-", "hours spent eating and/or listening")
tm = gpkit.Variable("\\tau_M", "-", "hours spent listening to music")
s = gpkit.Variable("s", "-", "savings accrued per day")
p = gpkit.Variable("p", 0.5, "-", "pay rate per unit productivity")
c = gpkit.Variable("c", 5, "-", "cost of new records, per hour")
te = gpkit.Variable("\\tau_E", 3 ,"-", "hours required to be spent eating")
gp = gpkit.GP( 1/s,
[p*tw**1.5*ts**0.75*tm**0.1 >= s + c*tm,
tw + ts + to <= 24,
to >= tm,
to >= te])
sol = gp.solve()
print sol.table()
In [11]:
from IPython import utils
from IPython.core.display import HTML
import os
def css_styling():
"""Load default custom.css file from ipython profile"""
base = utils.path.get_ipython_dir()
styles = "<style>\n%s\n</style>" % (open(os.path.join(base,'profile_default/static/custom/custom.css'),'r').read())
return HTML(styles)
css_styling()
Out[11]: